//
//  EGlobalAppData.m
//  AppRanking
//
//  Created by Gang.Wang on 12-11-19.
//  Copyright (c) 2012年 Gang.Wang. All rights reserved.
//

#import "EGlobalAppData.h"
#import "mcf.h"

#define  _SPY_APP_ARRAY_                   @"spy_app_list"


@implementation EGlobalAppData

SYNTHESIZE_SINGLETON_FOR_CLASS(EGlobalAppData)


- (void) dealloc
{
    [super dealloc];
}

- (NSArray *) spyAppArray
{
    NSUserDefaults*defaults = [NSUserDefaults standardUserDefaults];
    return [defaults arrayForKey:_SPY_APP_ARRAY_];;
}


- (void) spyNewApp:(NSString *) appId
{
    if ([NSString isNilOrEmpty:appId])
    {
        return;
    }
    
    NSMutableArray * spyAppArray = [NSMutableArray arrayWithArray:[self spyAppArray]];
    if([spyAppArray containsObject:appId])
    {
        return;
    }

    [spyAppArray addObject:appId];
    NSUserDefaults*defaults = [NSUserDefaults standardUserDefaults];
    [defaults setValue:spyAppArray forKey:_SPY_APP_ARRAY_];
    [defaults synchronize];

}


+ (NSString *) appDataFilePath:(NSString *) appId
{
    if ([NSString isNilOrEmpty:appId])
    {
        return nil;
    }
    
    
    return [YPath Combine:kDocuments combinePath:[NSString stringWithFormat:@"%@.data", appId]];
}

@end
